import java.util.concurrent.Semaphore;

/**
 * This class represents a grading job to be run concurrently with other jobs.
 */
public class ConcurrentGradingJob implements Runnable {
	Semaphore semJobs;
	Submission submission;
    /**
     * The constructor should store the submission and semaphore as private instance variables. These variables will
     * then be used in the run() method.
     */
    public ConcurrentGradingJob (Submission submission, Semaphore semaphore) {
    	semJobs = semaphore;
    	this.submission = submission;
    }

    /**
     * This method should first acquire a slot in the semaphore with its acquire() method. Then, it should use a Grader
     * object to grade the job's submission. Finally, it should release the semaphore slot with the release() method.
     */
    public void run () {
    	try {
			semJobs.acquire();
		} catch (InterruptedException e) {
			return;
		}
    	Grader grader = new Grader();
    	grader.gradeSubmission(submission);
    	semJobs.release();    	
    }

}
